﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SpeechLib;

namespace MyVideo
{
    public partial class ReadEnglish : UserControl
    {
        List<EnglishWord> englishWordLis;
        public ReadEnglish()
        {
            InitializeComponent();
            englishWordLis = new List<EnglishWord>();
            englishWordLis.Add(new EnglishWord() { Name = "illusion" });
            englishWordLis.Add(new EnglishWord() { Name = "mutual" });
            englishWordLis.Add(new EnglishWord() { Name = "divorce" });
            englishWordLis.Add(new EnglishWord() { Name = "citizenship" });
            englishWordLis.Add(new EnglishWord() { Name = "indication" });
            englishWordLis.Add(new EnglishWord() { Name = "suspect" });
            englishWordLis.Add(new EnglishWord() { Name = "hesitate" });
            englishWordLis.Add(new EnglishWord() { Name = "proceed" });
            englishWordLis.Add(new EnglishWord() { Name = "quote" });
            englishWordLis.Add(new EnglishWord() { Name = "racist" });
            englishWordLis.Add(new EnglishWord() { Name = "devotion" });
            englishWordLis.Add(new EnglishWord() { Name = "resistance" });
        }

        protected override void OnResize(EventArgs e)
        {
            panelEx1.Location = new Point((this.Width - panelEx1.Width) / 2, (this.Height - panelEx1.Height - 80) / 2);
            base.OnResize(e);
        }

        private void ReadEnglish_Load(object sender, EventArgs e)
        {
            IList<string> unitList = new List<string>();
            for (int i = 1; i <= 10; i++)
            {
                unitList.Add("Unit" + i);
            }
            comboBoxEx1.DataSource = unitList;
        }

        private void switchButton1_ValueChanged(object sender, EventArgs e)
        {
            timer1.Enabled = switchButton1.Value;
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            Random random = new Random(5000);
            int count = englishWordLis.Count - 1;
            SpeechVoiceSpeakFlags spFlags = SpeechVoiceSpeakFlags.SVSFlagsAsync;//异步说话SVSFlagsAsync，阻塞主线程SVSFDefault
            SpVoice voice = new SpVoice();
            voice.Speak(englishWordLis[random.Next(count)].Name, spFlags);
        }

        private void buttonX2_Click(object sender, EventArgs e)
        {
            if (timer1.Enabled)
            {
                listBox1.Items.Add(labelX1.Text);
            }
        }
    }
    class EnglishWord
    {
        public string Name { get; set; }
    }

}
